<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {



    
	//系统首页
    public function index(){

        $category = D('Category')->getTree();
        $lists    = D('Document')->lists(null);

        $this->assign('category',$category);//栏目
        $this->assign('lists',$lists);//列表
        $this->assign('page',D('Document')->page);//分页

                 
        $this->display();
    }

    public function header(){
        $list = M('shuju')
            ->find();
        $this->assign('list',$list);
        $this->display();
    }
    /*
 * 最新公告
 * @ document 关联表
 * @ picture 公告图片表
 * @ document_article 公告详情表
 * @ category 公告目录表
 * @ return string list 返回数据
 * @ return string c_id 返回点击id
 * */
    public function rankings(){
        $list = M('document')
            ->alias('d')
            ->join('lz88_picture as p ON p.id= d.cover_id')
            ->join('lz88_document_article as e ON e.id=d.id')
            ->join('lz88_category as c ON c.id=d.category_id ')
            ->where(array('d.category_id'=>$_POST['c_id']?$_POST['c_id']:'45'))
            ->field('p.path,e.id,c.title,d.update_time')
            ->select();
        $this ->assign('list',$list);
        $this -> assign('c_id',$_POST['c_id'] );
        $this->display();
    }

    //行情新闻
    public function news(){
        $resu = array('code' => 1,'msg' => '行情新闻查询成功!','data' ,'img'=> array());
        $dt = M('document')
            ->alias('d')
            ->join('lz88_picture as p ON p.id = d.cover_id')
            ->field('p.path,d.title,d.id')
            ->select();
        if($dt){
            $resu['data'] = $dt;
        }else{
            $resu['msg'] = '行情新闻查询失败!';
        }
        $this -> ajaxReturn($resu);

    }
    //行情新闻详情
    public function news_details(){
        $resu = array('code' => 1,'msg' => '行情新闻详情查询成功!','data' => array());
        $dt = M('document')
            ->alias('d')
            ->join('lz88_picture as p ON p.id = d.cover_id')
            ->join('lz88_document_article as e ON e.id = d.id')
            ->where(array('d.id'=>$_POST['id']))
            ->field('p.path,e.content,d.title')
            ->find();
        if($dt){
            $resu['data'] = $dt;
        }else{
            $resu['msg'] = '行情新闻详情查询失败!';
        }
        $this -> ajaxReturn($resu);
    }
    //价格表
    public function shuju(){
        $resu = array('code' => 1,'msg' => '数据发送成功!','data' => array());
        $dt = M('price')->select();
        $resu['data'] = $dt;
        $this -> ajaxReturn($resu);
    }
    //折线图
    public function zhexiantu(){
        $resu = array('code' => 1,'msg' => '数据发送成功!','data' => array());
//        $list = M('data_table')->field('color,dates,data,volumes')->select();
        $list = "https://api.feixiaohao.com/platformrank/bithumb/";
        $resu['data'] = $list;
        $this -> ajaxReturn($resu);
    }
    //公司名称
    public function company(){
        $resu = array('code' => 1,'msg' => '公司名称查询成功!','data' => array());
        $dt = M('company');
        $data = $dt->field('companyname')->select();
        if($data){
            $resu['data'] = $data;
        }else{
            $resu['msg'] = '公司名称查询失败!';
        }
        $this -> ajaxReturn($resu);
    }
}